package com.second.market.controller;

import com.second.common.pojo.RR;
import com.second.market.pojo.entity.Advertise;
import com.second.market.pojo.vo.AdvertiseVo;
import com.second.market.service.AdvertiseService;
import com.second.market.service.CustomerPlaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: clms-second
 * @description: 广告管理的控制类
 * @author: 邓衡
 * @create: 2021-07-23 18:07
 **/
@RestController
@RequestMapping("market/Advertise")
public class AdvertiseController {

    @Autowired
    private AdvertiseService advertiseService;

    @Autowired
    private CustomerPlaceService customerPlaceService;

    //查询
    @PostMapping("initAdvertiseTable/{currentPage}/{pageSize}")
    public RR initAdvertiseTable(@PathVariable("currentPage") Integer currentPage,
                                 @PathVariable("pageSize") Integer pageSize,
                                  @RequestBody AdvertiseVo advertiseVo
    ){
        return advertiseService.finAllAdvertiseByPage(currentPage,pageSize,advertiseVo);

    }

    //添加
    @PostMapping("insert")
    public RR insert(@RequestBody Advertise advertise) {
        return advertiseService.insert(advertise);
    }
    //修改
    @PutMapping("update")
    public RR updatte(@RequestBody Advertise advertise){
        return advertiseService.update(advertise);
    }

    //回显
    @GetMapping("selectById/{id}")
    public RR selectById(@PathVariable Integer id){
        return advertiseService.selectById(id);
    }

    //删除
    @DeleteMapping
    public RR delete(@RequestParam  Integer id){
        return advertiseService.delete(id);
    }

    //修改状态
    @PostMapping("updateStatus/{status}/{advertiseid}")
    public RR updateStatus(@PathVariable Integer status,
                           @PathVariable Integer advertiseid){
        return advertiseService.update(status,advertiseid);
    }

    //搜索place
    @PostMapping("selectPlace")
    public List<Map> selectPlace() {
        return advertiseService.selectPlace();
    }

}
